package com.ce.pms.log4ce;

import java.util.List;
import java.util.Map;

import org.aspectj.lang.JoinPoint;

import com.ce.component.log4ce.aop.constructor.support.AbstractOriginalObjectHolder;
import com.ce.component.log4ce.aop.constructor.support.OriginalObjectHolder;
import com.ce.component.log4ce.aop.parser.BizLogParser;
import com.ce.pms.common.web.ICacheManage;
import com.ce.pms.customer.vo.CustomerVO;
import com.ce.util.BlankUtil;

public class CustomerEditHolder extends AbstractOriginalObjectHolder implements OriginalObjectHolder{

	private Log4ceHelper log4ceHelper = Log4ceHelper.getInstance();

	private static final int UPDATE_OWNER_INFO = 1;
	static  final int CHANGE_OWNER = 2;
	protected Map<String, Object> getOriginalObjects(JoinPoint joinPoint, BizLogParser logParser) {

		Map<String,Object> map = logParser.getLogArguments(joinPoint);
		List<CustomerVO> customerList = (List<CustomerVO>)map.get("customerList");
		CustomerVO source = null;
		CustomerVO target = null;

		if(log4ceHelper.getEditMode(customerList)==UPDATE_OWNER_INFO)
		{
			CustomerVO customerVO  = customerList.get(0);
			Long id =  customerVO.getParticipantId();
			if(ICacheManage.EDIT.equals(customerVO.getOpratorStatus())){
				target = customerVO;
				source = log4ceHelper.getCustomerById(id, customerVO.getParticipantTypeCode());
				source.setParticipantTypeCode(customerVO.getParticipantTypeCode());
				source.setCustomerTypeCode(customerVO.getCustomerTypeCode());
			}
		}
		else if(log4ceHelper.getEditMode(customerList)==CHANGE_OWNER)
		{
			for(CustomerVO customerVO : customerList)
			{
				if(ICacheManage.DELETE.equals(customerVO.getOpratorStatus())){
					source = customerVO;
				}
				else if(ICacheManage.ADD.equals(customerVO.getOpratorStatus())){
					target = customerVO;
				}
			}
		}
		if(!BlankUtil.isBlank(source)){
			String srcHouseNumbers = log4ceHelper.genHouseNumbers(log4ceHelper.getSourceHouses(source.getParticipantId(),source.getCustomerTypeCode()));
			map.put("srcHouseNumbers", srcHouseNumbers);
		}
		map.put("sourceCustomerVO", source);
		map.put("targetCustomerVO", target);
		return map;
	}
}
